<?php
session_start();
if(array_key_exists('user_id', $_SESSION)){
	if($_SESSION['user_id']){
		header('location:home.php');
	}
}


//Fetch all requested parameters in array
$REQUESTED_DATA = $_POST;
$email = '';
$password = '';

$errorMessage = Array();
if($REQUESTED_DATA){
//Include files
$ROOT_DIR_PATH = "";
require_once($ROOT_DIR_PATH . "includes/includes.php");



//Initialization
$errorMessageArray = Array();
$JSONARRAY = Array(
    'STATUS' => 'FAILURE',
    'MESSAGES' => Array(),
);

//Filteration of the requested parameters
$filterArray = Array("TrimElement", "mysqlRealEscape");
$FILTERED_DATA = $GENOBJ->filter($REQUESTED_DATA, $filterArray);

$email = $FILTERED_DATA['email'];
$password = $REQUESTED_DATA['password'];



//Validation checks

if ($GENOBJ->IsEmpty($email)) {
    $errorMessage[] = 'Email address should not be blank.';
}if ($password == '') {
    $errorMessage[] = 'Password should not be blank';
} else if (!$GENOBJ->ValidEmailAddress($email)) {
    $errorMessage[] = 'Email address is not valid.';
}
if (count($errorMessage) <= 0) {
		$resultArray = array();
		$selectSql = "SELECT [login_id]
				  ,[login_email]
				  ,[login_password]
				  ,[login_status]
			  FROM [tble_login] 
			  Where login_email = '" . $email . "' and login_password = '".md5($password)."'
			  and login_status = 1";
		$resultArray = $DBOBJ->select($selectSql);
		if ($resultArray) {
			$responseArray = Array();
			$responseArray['Email'] = $resultArray['0']['login_email'];
			$responseArray['MemberId'] = $resultArray['0']['login_id'];
			$_SESSION['user_id'] =  $resultArray['0']['login_id'];
			header('location:home.php');
		}
		 else {
		   $errorMessage[] = 'Username and Password do not match.';
		}
} else {
   
}


}

?>

<!DOCTYPE html>
<html class="login-bg">
<head>
	<title>Login - seveneleven</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	
    <!-- bootstrap -->
    <link href="css/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-overrides.css" type="text/css" rel="stylesheet" />

    <!-- global styles -->
    <link rel="stylesheet" type="text/css" href="css/compiled/layout.css" />
    <link rel="stylesheet" type="text/css" href="css/compiled/elements.css" />
    <link rel="stylesheet" type="text/css" href="css/compiled/icons.css" />

    <!-- libraries -->
    <link rel="stylesheet" type="text/css" href="css/lib/font-awesome.css" />
    
    <!-- this page specific styles -->
    <link rel="stylesheet" href="css/compiled/signin.css" type="text/css" media="screen" />

    <!-- open sans font -->
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css' />

    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
</head>
<body>
  <div class="row-fluid login-wrapper">
        <a href="javascript:void(0)">
        </a>

        <div class="span4 box">
            <div class="content-wrap">
                <h6>Log in</h6>
				
				<?php 
				
				if (count($errorMessage) > 0): ?>
				<div class="alert alert-error">
				<?php foreach ($errorMessage as $erroValue): ?>
				
					<div class="text-left">
					<i class="icon-remove-sign"></i>
					<?php echo $erroValue; ?>
					</div>
					
				<?php endforeach; ?>
				</div>
				<?php endif; ?>
				<form action="index.php" method="post">
                <input class="span12" type="text" placeholder="E-mail address" name="email" id="email" value = <?php echo $email;?>>
                <input class="span12" type="password" placeholder="Your password" name="password" id="password" value = <?php echo $password;?>>
                <button type="submit" class="btn-glow primary login">
                Log in
				</button>
				</form>
            </div>
        </div>

        
    </div>

	<!-- scripts -->
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/theme.js"></script>

   
</body>
</html>